<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'bmap.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=gkhZkvMMhPRMs1ybtbM7nmhH1ryHr6Dp"></script>
<title>根据地址查询经纬度</title>
<script type="text/javascript" src="static/js/jquery.min.js"></script>

</head>
<body style="background:#CBE1FF">
	<div style="width:730px;margin:auto;">
		要查询的地址： <input id="text_" type="text" value="${address}" style="margin-right:100px;" /> 
		查询结果(经纬度)： <input id="result_" type="text" /> 
		<input type="button" value="查询" onclick="searchByStationName();" />
		<div id="container"
			style="position: absolute;
                margin-top:30px;
                width: 730px;
                height: 560px;
                top: 50;
                border: 1px solid gray;
                overflow:hidden;">
		</div>
	</div>
</body>
<script type="text/javascript">
	var map = new BMap.Map("container");
	map.centerAndZoom("黑龙江", 12);
	map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
	map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用

	map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
// 	map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
// 	map.addControl(new BMap.OverviewMapControl({
// 		isOpen : true,
// 		anchor : BMAP_ANCHOR_BOTTOM_RIGHT
// 	})); //右下角，打开

	var localSearch = new BMap.LocalSearch(map);
	localSearch.enableAutoViewport(); //允许自动调节窗体大小
	function searchByStationName() {
		map.clearOverlays(); //清空原来的标注
		var keyword = document.getElementById("text_").value;
		console.log(keyword);
		localSearch.setSearchCompleteCallback(function(searchResult) {
			console.log("3");
			var poi = searchResult.getPoi(0);
			
			document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat;
			map.centerAndZoom(poi.point, 13);
			var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat)); // 创建标注，为要查询的地方对应的经纬度
			map.clearOverlays();
			// marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
			var content = document.getElementById("text_").value + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat;
			var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
			marker.addEventListener("click", function() {
				this.openInfoWindow(infoWindow);
			});
			map.addOverlay(marker);
			console.log("4");
		});
		localSearch.search(keyword);
	}
    searchByStationName();
</script>
</html>
